<template>
  <router-view />
</template>
<script>
import { getProjectDict, getOrgTree, getAllOrgTree } from '../api/commom'
import { useStore } from 'vuex'
import { defineComponent } from 'vue'
import { servicesLoading } from '@/views/project/project-manage/loading'

export default defineComponent({
  name: 'project-manage',
  setup() {
    //
  },
  created() {
    const store = useStore()
    console.log(this, 'this')
    if (Object.keys(store.state.projectCenter.projectDict).length == 0) {
      const loading = servicesLoading({ fullscreen: true,text:'加载字典数据' })
      getProjectDict().then((res) => {
        loading.close()
        store.state.projectCenter.projectDict = res.data.data
        console.log(store.state.projectCenter.projectDict, 'store.state.projectCenter.projectDict')
      }).catch(()=>{
        loading.close()
      })
    }
    // if (Object.keys(store.state.projectCenter.ZhongziConfig).length == 0) {
    //   getZhongziConfig().then((res) => {
    //     store.state.projectCenter.ZhongziConfig = res.data.data
    //     console.log(store.state.projectCenter.ZhongziConfig, 'store.state.projectCenter.ZhongziConfig')
    //   })
    // }
    if (store.state.projectCenter.orgList.length == 0) {
      // const loading = servicesLoading({ fullscreen: true })
      getOrgTree().then((res) => {
        // loading.close()
        store.state.projectCenter.orgList = res.data.data
        store.state.projectCenter.orgDefaultExpandedKeys = res.data.data.map((item) => item.id)
        ergodicOrg(store.state.projectCenter.orgList)
        console.log(store.state.projectCenter.orgList, 'store.state.projectCenter.orgList')
      })
    }
    if (store.state.projectCenter.allOrgList.length == 0) {
      getAllOrgTree().then((res) => {
        store.state.projectCenter.allOrgList = res.data.data
        ergodicOrg(store.state.projectCenter.allOrgList)
        console.log(store.state.projectCenter.allOrgList, 'store.state.projectCenter.allOrgList')
      })
    }
    const ergodicOrg = (orgList) => {
      orgList.forEach((element) => {
        element.label = element.name
        element.value = element.id
        if (element.children) {
          ergodicOrg(element.children)
        }
      })
    }
  },
})
</script>
